const Koa = require('koa');

const app = new Koa();

const path = require('path');

//1.处理静态资源

const static = require('koa-static');

const Router = require('koa-router');

const router = new Router();

const query = require('./db/query.js');

app.use(static(path.join(__dirname,'./public')));

//2.路由功能

app.use(router.routes());

app.use(router.allowedMethods());

//3.接口

router.get('/api/userlist',async (ctx,next) => {
    //hello
    
    //mysql数据库
    let data = await query('select * from userlist');

    ctx.body = data
})

app.listen(3000,() => {
    console.log("服务启动成功");
})